package com.example.day15;

import android.app.Activity;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;
import java.util.Map;

public class MyAdapter3 extends BaseAdapter {
    public static int num=0;
    Activity activity;
    List<Map<String,Object>> list1;
    public MyAdapter3(Activity activity,List<Map<String,Object>> list1){
        this.activity=activity;
        this.list1=list1;
    }
    @Override
    public int getCount() {
        return list1.size();
    }

    @Override
    public Object getItem(int position) {
        return list1.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View  view =View.inflate(activity, R.layout.test_item, null);
        TextView text = view.findViewById(R.id.text1);
        Map<String,Object> map= list1.get(position);
        text.setText(map.get("title").toString());
//        viewHolder viewh;
//        if(convertView==null){
//            convertView = View.inflate(activity, R.layout.test_item, null);
//            convertView.setId(num);
//            num++;
//            viewh = new viewHolder();
//            viewh.text1 = convertView.findViewById(R.id.text1);
//            viewh.text2 = convertView.findViewById(R.id.text2);
//            viewh.image = convertView.findViewById(R.id.image1);
//            convertView.setTag(viewh);
//        }else{
//            viewh=(viewHolder)convertView.getTag();
//        }
//        Log.e("convertView.getId();",convertView.getId()+"");
//        Map<String,Object> map= list1.get(position);
//        Log.e("######"+position,map.get("title").toString());
//        viewh.text1.setText(map.get("title").toString());
//        viewh.text2.setText(map.get("food_str").toString());
//        viewh.image.setImageBitmap((Bitmap)map.get("pic"));
//        viewh.text1.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Log.e("######","");
//            }
//        });
//        return convertView;
        return view;
    }
    public class viewHolder{
        TextView text1 ;
        TextView text2 ;
        ImageView image;
    }
}
